package com.onlinemathuracrud.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.onlinemathuracrud.dao.GhatOrKundDao;
import com.onlinemathuracrud.model.GhatOrKund;


@Controller
@RequestMapping(value="/ghatorkund")
public class GhatOrKundController {
	@Autowired
	GhatOrKundDao ghatorkundDao;
	@RequestMapping(value="/showghatorkunds" , method = RequestMethod.GET)
	public String showGhatOrKunds(ModelMap model,@ModelAttribute("ghatorkunddata") GhatOrKund ghatorkund) {

		model.addAttribute("allghatorkunds", ghatorkundDao.findAll());
		return "ghatorkund";
	}
	
	@RequestMapping(value="/editghatorkund/{id}" , method = RequestMethod.GET)
	public String editghatorkund(ModelMap model,@PathVariable("id")Long ghatorkundId) {
		
		model.addAttribute("ghatorkunddata",ghatorkundDao.findById(ghatorkundId));
		model.addAttribute("allghatorkund",ghatorkundDao.findAll());
		return "ghatorkund";
	}
	
	@RequestMapping(value="/deleteghatorkund/{id}" , method = RequestMethod.GET)
	public String deleteghatorkund(ModelMap model,@PathVariable("id")Long ghatorkundId,@ModelAttribute("ghatorkunddata")  GhatOrKund ghatorkund) {
		
		ghatorkundDao.delete(ghatorkundDao.findById(ghatorkundId));
		model.addAttribute("allghatorkunds",ghatorkundDao.findAll());
		return "ghatorkund";
	}
	
	
	@RequestMapping(value="/saveghatorkund" , method = RequestMethod.POST)
	public String saveghatorkund(ModelMap model, @ModelAttribute("ghatorkunddata") GhatOrKund ghatorkund) {

		ghatorkundDao.saveOrUpdate(ghatorkund);
		model.addAttribute("allghatorkunds",ghatorkundDao.findAll());
		return "ghatorkund";

	
}}
